
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const baseConfig = require('./webpack.base.js')

const prodConfig = {
  entry: baseConfig.entry,
  output: {
    path: baseConfig.output.path,
    filename: 'js/[name]_[contenthash:8].js',
    chunkFilename: 'js/[name]_chunk_[contenthash:6].js'
  },
  module: {
    rules: [
      {
        test: /\.vue$/,
        loader: 'vue-loader'
      },
      {
        oneOf: [
          ...baseConfig.commonRules,
          {
            test: /\.css$/,
            use: [
              MiniCssExtractPlugin.loader,
              'css-loader',
              'postcss-loader'
            ]
          },
          {
            test: /\.less$/,
            use: [
              MiniCssExtractPlugin.loader,
              'css-loader',
              'postcss-loader',
              'less-loader'
            ]
          }
        ]
      }
    ]
  },
  plugins: [
    ...baseConfig.commonPlugins,
    new MiniCssExtractPlugin({
      filename: 'css/[name].css'
    })
  ],
  resolve: baseConfig.commonResolve,
  optimization: baseConfig.commonOptimization,
  devtool: 'source-map',
  mode: 'production'
}

module.exports = prodConfig;
